from my_http import MyHttp
import urllib.request
from bs4 import BeautifulSoup
import glob
import jieba
import re
import json

file = open('./out/shenjiaosuo_zhishu_list_data.txt', 'w', encoding = 'utf-8')
file_name = open('./out/shenjiaosuo_zhishu_list_name.txt', 'w', encoding = 'utf-8')

class SzZhishu:
    def __init__(self):
        pass
        
    def get_http_data(self):
        for i in range (1, 70):
            #url = "http://www.szse.cn/api/report/ShowReport/data?SHOWTYPE=JSON&CATALOGID=1747_zs&TABKEY=tab1&PAGENO=" + str(i) + "&ZSDM=399001&random=0.653174650818769"
            url = "http://www.cnindex.com.cn/index/indexList?channelCode=-1&rows=20&pageNum=" + str(i)
            json_http = MyHttp.http_json_data(url)
            json_data = json.loads(json_http)
            total = int(json_data["data"]["total"])
            for data in json_data["data"]["rows"]:
                data_code = data["indexcode"]
                data_name = data["indexname"]
                data_all = "SZ|" + data_code + "|" + data_name + "|" + "http://www.cnindex.com.cn/module/index-detail.html?act_menu=1&indexCode=" + data_code + "|"
                file.write("SZ" + data_code + "," + data_all + "\n")
                file_name.write(data_name + "\n")
            if total <= (i * 20):
                break

if __name__ == '__main__':
    code = SzZhishu()
    code.get_http_data()
    file.close()
    file_name.close()